<template>
	<view class="body">
		<!-- 话题详情 -->
		<topic-info :item='topicInfo'></topic-info>
		<!-- tabbar切换 -->
		<tabBar :tabBars="tabBars" :tabIndex="tabIndex" @toIndex='toIndex' :scrollItemstyle='"width:50%"'></tabBar>
		<!-- 列表 -->
		<view class="topic-detail-list">
			<block v-for="(item,index) in tabList" :key='index'>
				<template v-if="tabIndex==index">
					<!-- 列表 -->
					<block v-for="(list,listIndex) in item.list" :key="listIndex">
						<common-list :item="list"></common-list>
					</block>
					<!-- 上拉加载 -->
					<loadMore :loadtext="item.textload"></loadMore>
				</template>
			</block>
		</view>
	</view>
</template>

<script>
	import topicInfo from '../../components/topic/topic-info.vue'
	import tabBar from '../../components/tabbar/tabbar.vue'
	import commonList from "../../components/common-list/common-list.vue";
	import loadMore from '../../components/common/load-more.vue'
	import noThing from '../../components/no-thing/no-thing.vue'
	export default {
		components: {
			topicInfo,
			tabBar,
			commonList,
			loadMore,
			noThing
		},
		data() {
			return {
				tabIndex: 0,
				topicInfo: {
					titlepic: '../../static/demo/topicpic/13.jpeg',
					title: '忆往事，敬余生',
					desc: "我是描述",
					totalnum: '793',
					todaynum: "641"
				},
				tabBars: [{
						name: '默认',
						id: 'moren'
					},
					{
						name: '最新',
						id: 'zuixin'
					}
				],
				tabList: [{
						textload: "加载更多...",
						list: [{
								userpic: '../../static/demo/userpic/4.jpg',
								username: '哈哈',
								sex: 1, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '../../static/demo/datapic/9.jpg',
								video: {
									looknum: "20w",
									long: '2:47'
								},
								share: false,
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
							// 分享
							{
								userpic: '../../static/demo/userpic/7.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '',
								video: false,
								share: {
									title: '我是分享标题',
									titlepic: '../../static/demo/datapic/42.jpg'
								},
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
							{
								userpic: '../../static/demo/userpic/6.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '../../static/demo/datapic/10.jpg',
								video: {
									looknum: "20w",
									long: '2:47'
								},
								share: false,
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
							{
								userpic: '../../static/demo/userpic/6.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '../../static/demo/datapic/7.jpg',
								video: {
									looknum: "20w",
									long: '2:47'
								},
								share: false,
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
						]
					},
					{
						textload: "加载更多...",
						list: [{
								userpic: '../../static/demo/userpic/4.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 26,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '../../static/demo/datapic/9.jpg',
								video: {
									looknum: "20w",
									long: '2:47'
								},
								share: false,
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
							// 分享
							{
								userpic: '../../static/demo/userpic/7.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '',
								video: false,
								share: {
									title: '我是分享标题',
									titlepic: '../../static/demo/datapic/42.jpg'
								},
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
							{
								userpic: '../../static/demo/userpic/6.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '../../static/demo/datapic/10.jpg',
								video: {
									looknum: "20w",
									long: '2:47'
								},
								share: false,
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
							{
								userpic: '../../static/demo/userpic/6.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '../../static/demo/datapic/7.jpg',
								video: {
									looknum: "20w",
									long: '2:47'
								},
								share: false,
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
						]
					},
				]
			}
		},
		onReachBottom() {
			this.loadmore()
		},
		onPullDownRefresh() {
				this.getdata()
		},
		methods: {
			toIndex(data){
				console.log()
				this.tabIndex = data
			},
			// 下拉刷新
			getdata(){
				
				
				setTimeout(()=>{
					let arr = [
						{
								userpic: '../../static/demo/userpic/4.jpg',
								username: '哈哈111111',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题111111',
								titlepic: '../../static/demo/datapic/9.jpg',
								video: {
									looknum: "20w",
									long: '2:47'
								},
								share: false,
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
							// 分享
							{
								userpic: '../../static/demo/userpic/7.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '',
								video: false,
								share: {
									title: '我是分享标题',
									titlepic: '../../static/demo/datapic/42.jpg'
								},
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
							{
								userpic: '../../static/demo/userpic/6.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '../../static/demo/datapic/10.jpg',
								video: {
									looknum: "20w",
									long: '2:47'
								},
								share: false,
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
							{
								userpic: '../../static/demo/userpic/6.jpg',
								username: '哈哈',
								sex: 0, // 0 男，1 女
								age: 25,
								isguanzhu: false,
								title: '我是标题',
								titlepic: '../../static/demo/datapic/7.jpg',
								video: {
									looknum: "20w",
									long: '2:47'
								},
								share: false,
								path: "深圳 龙岗",
								sharenum: 20,
								commentnum: 30,
								goodnum: 20
							},
						
					]
					this.tabList[this.$store.getters.getTabIndex].list = arr;
					uni.stopPullDownRefresh();
				},2000)
			},
			// 上拉加载更多
			loadmore() {
				console.log('shangl')
				console.log(this.$store.getters.getTabIndex)

				if (this.tabList[this.$store.getters.getTabIndex].textload !== '加载更多...') {
					return;
				}
				this.tabList[this.$store.getters.getTabIndex].textload = '加载中'
				console.log(this.tabList[this.$store.getters.getTabIndex].textload)
				// this.guanzhu.loadtext = '没有更多'
				setTimeout(() => {
					let obj = {
						userpic: '../../static/demo/userpic/4.jpg',
						username: '哈哈',
						sex: 0, // 0 男，1 女
						age: 25,
						isguanzhu: false,
						title: '我是标题',
						titlepic: '../../static/demo/datapic/9.jpg',
						video: {
							looknum: "20w",
							long: '2:47'
						},
						share: false,
						path: "深圳 龙岗",
						sharenum: 20,
						commentnum: 30,
						goodnum: 20
					}
					this.tabList[this.$store.getters.getTabIndex].list.push(obj)
					this.tabList[this.$store.getters.getTabIndex].textload = '加载更多...'
				}, 1000);
			},
		}
	}
</script>

<style scoped>
	.body{
		/* padding: 0 20upx; */
	}
</style>
